package main

import "fmt"

func main() {

	map1 := map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
		"d": 4,
		"e": 5,
	}

	fmt.Println("map = ", map1)
	/**
	遍历map使用range
	*/
	for k, v := range map1 {
		fmt.Printf("\nk=%s, v=%d", k, v)
	}

	fmt.Println("print the not exist: ", map1["123"])

	if num, ok := map1["123"]; ok {
		fmt.Println("num is ", num)
	} else {
		fmt.Println("key does not exist: 123")
	}

	//定义一个新map

	map2 := make(map[string]int)
	var map3 map[string]int //nil
	fmt.Println(map2, map3)

	/**
	nil map 不能存放值

	panic: assignment to entry in nil map

	goroutine 1 [running]:
	main.main()
		/Users/ddy/go/src/hongen.com/go-test/main/map.go:37 +0x54c
	*/
	//map3["1"] = 1

}
